﻿using D.B.Data.API.Applications.Command.LeaveCommand;
using D.B.Data.Domain;
using D.B.Data.Domain.DTO.Output;
using D.B.Data.ErrorCode;
using D.B.Data.Infrastructuse;
using MediatR;

namespace D.B.Data.API.Applications.CommandHandler.LeaveCommandHandler
{
    public class QuerDeptCommandHandler : IRequestHandler<QuerDeptCommand, APIResult<List<GetDeptIdNameOutput>>>
    {
        private readonly IBaseRepository<DeptModel> baseRepository;

        public QuerDeptCommandHandler(IBaseRepository<DeptModel> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public Task<APIResult<List<GetDeptIdNameOutput>>> Handle(QuerDeptCommand request, CancellationToken cancellationToken)
        {
            var res = baseRepository.GetAll().Where(s => !s.IsDel).Select(s =>new GetDeptIdNameOutput
            {
                DeptName=s.DeptName,
                Id=s.Id

            });
            APIResult<List<GetDeptIdNameOutput>> result = new APIResult<List<GetDeptIdNameOutput>>()
            {
                Code = EnumCode.Ok,
                Msg = "成功",
                Data=res.ToList()
            };

            return Task.FromResult(result);
        }
    }
}
